package com.xxx.ware.ware_manage_sys.controller.record;

import com.xxx.ware.ware_manage_sys.bean.dto.OptQueryDto;
import com.xxx.ware.ware_manage_sys.bean.dto.WebResultDto;
import com.xxx.ware.ware_manage_sys.bean.vo.OptRecordVo;
import com.xxx.ware.ware_manage_sys.bean.vo.ResultVo;
import com.xxx.ware.ware_manage_sys.service.IErrRecordService;
import com.xxx.ware.ware_manage_sys.service.IOptRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "操作记录")
@RestController
@RequestMapping("/wms/record")
@Slf4j
public class OptRecordController {

    @Autowired
    private IOptRecordService optRecordService;

    @Autowired
    private IErrRecordService errRecordService;

    @PostMapping("/optList")
    @ApiOperation(value = "操作记录列表", notes = "操作记录列表", httpMethod = "POST")
    public ResultVo<WebResultDto<OptRecordVo>> optList(@RequestBody @Validated OptQueryDto optQueryDto){
        try {
            return ResultVo.data(optRecordService.getOptRecordList(optQueryDto));
        } catch (Exception e) {
            log.error("获取操作列表失败，对应失败原因：" + e.getMessage());
            return ResultVo.fail("获取操作列表失败");
        }
    }

    @GetMapping("/rePushErrRecordMsg")
    @ApiOperation(value = "异常消息重新处理", notes = "异常消息重新处理", httpMethod = "GET")
    public ResultVo<String> rePushErrRecordMsg(@RequestParam("recordId") String recordId,
                                               @RequestParam("optModule") String optModule){
        try {
            errRecordService.handleErrRecordMsg(recordId, optModule);
            return ResultVo.data("操作成功");
        } catch (Exception e) {
            log.warn("消息重新处理异常，异常原因：{}", e.getMessage());
            return ResultVo.fail("消息重新处理异常");
        }
    }

}
